package com.agy.filemanager.service.impl;

import com.agy.filemanager.common.StringUtils;
import com.agy.filemanager.entity.DcDocUserFile;
import com.agy.filemanager.entity.SessionInfo;
import com.agy.filemanager.mapper.DcSystemUserFileDao;
import com.agy.filemanager.service.DcSystemUserFileService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class DcSystemUserFileServiceImpl implements DcSystemUserFileService{

    @Autowired
    private DcSystemUserFileDao dcSystemUserFileDao;

    /**
     * 查询表格数据
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public Page selectTable(int pageNum, int pageSize, String name) {
        Page page = PageHelper.startPage(pageNum,pageSize);
        Example example = new Example(DcDocUserFile.class);
        Example.Criteria criteria = example.createCriteria();
        if(name != null && !name.equals("")){
            criteria.andLike("docname","%"+name+"%");
        }
        List<DcDocUserFile> list = this.dcSystemUserFileDao.selectByExample(example);
        return page;
    }

    /**
     * 设置权限
     * @param id
     */
    @Override
    public void operateById(String id,String sign,SessionInfo info) {
         DcDocUserFile entity = new DcDocUserFile();
         entity.setId(id);
         entity.setStatus(new Byte("1"));
         entity.setTime(StringUtils.getTime());
         entity.setAuthority(new Byte(sign));//0:无权1:浏览 2:下载
         entity.setApprover(info.getId());
         entity.setApproverName(info.getName());
         this.dcSystemUserFileDao.updateByPrimaryKeySelective(entity);
    }
}
